package br.com.mundodaprata.store.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@NamedQueries({@NamedQuery(name="userByName", query="select u from User u where u.username like :name")})
@Entity
@Table(name="users")
public class User extends AbstractEntity {
   
   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   @Column
   private Long  code;
   
   @Column(unique=true, nullable=false)
   private String   username;
   
   @Column(nullable=false)
   private String   password;
   
   @Enumerated(EnumType.STRING)
   @Column(name="user_type")
   private UserType type;
   
   public Long getCode() {
      return code;
   }
   
   public void setCode(Long code) {
      this.code = code;
   }
   
   public String getUsername() {
      return username;
   }
   
   public void setUsername(String username) {
      this.username = username;
   }
   
   public String getPassword() {
      return password;
   }
   
   public void setPassword(String password) {
      this.password = password;
   }
   
   public UserType getType() {
      return type;
   }
   
   public void setType(UserType type) {
      this.type = type;
   }
   
   @Override
	public String toString() {
		StringBuilder result = new StringBuilder();
		
		result.append(getCode())
		      .append(" - ")
		      .append(getUsername());
		
		return result.toString();
	}
}